﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Reflection;

namespace DNA.Mvc.Management
{
    [Table("aspnet_WebEvent_Events"),Serializable,XmlRoot("logEntry")]
    public class EventLogEntry
    {
        public EventLogEntry() { }

        [Key, MaxLength(32)]
        public string EventID { get; set; }

        /// <summary>
        /// Date and time of the log entry message.
        /// </summary>
        public virtual DateTime EventTimeUtc { get; set; }

        public virtual DateTime EventTime { get; set; }

        [MaxLength(256)]
        public virtual string EventType { get; set; }

        public virtual decimal EventSequence { get; set; }

        public virtual decimal EventOccurrence { get; set; }

        public virtual int EventCode { get; set; }

        public virtual int EventDetailCode { get; set; }

        /// <summary>
        /// The summary of the log message.
        /// </summary>
        [MaxLength(1024)]
        public virtual string Message { get; set; }

        /// <summary>
        /// The detail of the log message.Use to record the exception message detail.
        /// </summary>
        [Column(TypeName = "ntext")]
        public virtual string Detail { get; set; }

        /// <summary>
        /// Gets /Sets the user who responsible this log message.
        /// </summary>
        [MaxLength(256)]
        public virtual string UserName { get; set; }

        [MaxLength(256)]
        public string ApplicationPath { get; set; }

        [MaxLength(256)]
        public string ApplicationVirtualPath { get; set; }

        [MaxLength(256)]
        public string MachineName { get; set; }

        /// <summary>
        /// Gets/Sets the current request raw url
        /// </summary>
        [MaxLength(1024)]
        public virtual string RequestUrl { get; set; }

        [MaxLength(256)]
        public virtual string ExceptionType { get; set; }

        public virtual Guid RelatedActivityId { get; set; }

        private System.Diagnostics.TraceEventType severity = System.Diagnostics.TraceEventType.Information;

        [NotMapped]
        public System.Diagnostics.TraceEventType Severity
        {
            get { return severity; }
            set { severity = value; }
        }

        //public override string ToString()
        //{
        //    var attr = BindingFlags.Public | BindingFlags.Instance;
        //    var dict = new Dictionary<string, object>();
        //    foreach (var property in this.GetType().GetProperties(attr))
        //    {
        //        if (property.CanRead)
        //        {
        //            dict.Add(property.Name, property.GetValue(this, null));
        //        }
        //    }

        //    //return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this);
        //}
    }
}
